brecke<-read.csv("XXXXXX/Brecke Conflict Catalogue.csv")

jaques<-read.csv("XXXX/HCED Master Data.csv")


timeline<-seq(1400,2003,1)

jaques_years<-as.character(jaques$Year)

jaques_totals<-NULL


for (i in 1:length(jaques_years)){

temp<-jaques_years[i]

if (grepl("-",temp)==T & strsplit(temp,"-")[[1]][1]!="") {

temp<-seq(strsplit(temp,"-")[[1]][1],strsplit(temp,"-")[[1]][2],1)

}

jaques_totals<-c(jaques_totals,temp)

}

new_jaques<-as.numeric(jaques_totals)

jaques_time<-apply(as.matrix(timeline),1,function(x) sum(new_jaques==x))

brecke_time<-NULL

for (i in 1:dim(brecke)[1]){

if (i!=229 & !is.na(brecke$StartYear[i]) & !is.na(brecke$EndYear[i])){

temp<-seq(brecke$StartYear[i],brecke$EndYear[i],1)

brecke_time<-c(brecke_time,temp)
}

}

brecke_time2<-apply(as.matrix(timeline),1,function(x) sum(brecke_time==x))


plot(timeline,jaques_time,type="l")
plot(timeline,brecke_time2,type="l")

yrs<-NULL
fallen<-NULL


for (i in 1:dim(brecke)[1]){

if (!is.na(brecke$StartYear[i]) & !is.na(brecke$EndYear[i]) & !is.na(brecke$TotalFatalities[i])){

waryears<-length(seq(brecke$StartYear[i],brecke$EndYear[i],1))

years<-seq(brecke$StartYear[i],brecke$EndYear[i],1)

fatalities<-brecke$TotalFatalities[i]/waryears

dead<-rep(fatalities,length(years))

yrs<-c(yrs,years)
fallen<-c(fallen,dead)

}

}

brecke_dead<-apply(as.matrix(timeline),1,function(x) sum(fallen[yrs==x],na.rm=T))

plot(timeline,brecke_dead,type="l")
plot(timeline,jaques_time,type="l")

png("Brecke Jaques Comparison.png")
par(mfrow=c(2,1))
plot(timeline,brecke_dead,type="l",xlab="Year",ylab="Brecke Deaths")
plot(timeline,jaques_time,type="l",xlab="Year",ylab="Jaques Battles")
dev.off()

yrs<-NULL
fallen<-NULL


for (i in 1:dim(brecke)[1]){

if (!is.na(brecke$StartYear[i]) & !is.na(brecke$EndYear[i]) & !is.na(brecke$MilFatalities[i])){

waryears<-length(seq(brecke$StartYear[i],brecke$EndYear[i],1))

years<-seq(brecke$StartYear[i],brecke$EndYear[i],1)

fatalities<-brecke$MilFatalities[i]/waryears

dead<-rep(fatalities,length(years))

yrs<-c(yrs,years)
fallen<-c(fallen,dead)

}

}

brecke_dead<-apply(as.matrix(timeline),1,function(x) sum(fallen[yrs==x],na.rm=T))

plot(timeline,brecke_dead,type="l")
plot(timeline,jaques_time,type="l")

png("Brecke Jaques Comparison.png")
par(mfrow=c(2,1))
plot(timeline,brecke_dead,type="l",xlab="Year",ylab="Brecke Deaths")
plot(timeline,jaques_time,type="l",xlab="Year",ylab="Jaques Battles")
dev.off()




